package com.ruoyi.people.recharge.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.people.users.domain.User;
import com.ruoyi.people.users.mapper.UserMapper;
import com.ruoyi.people.users.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.people.recharge.mapper.RechargeMapper;
import com.ruoyi.people.recharge.domain.Recharge;
import com.ruoyi.people.recharge.service.IRechargeService;

/**
 * 充值记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-07
 */
@Service
public class RechargeServiceImpl implements IRechargeService 
{
    @Autowired
    private RechargeMapper rechargeMapper;

    @Autowired
    private UserMapper userMapper;
    /**
     * 查询充值记录
     * 
     * @param rechargeId 充值记录主键
     * @return 充值记录
     */
    @Override
    public Recharge selectRechargeByRechargeId(Long rechargeId)
    {
        return rechargeMapper.selectRechargeByRechargeId(rechargeId);
    }

    /**
     * 查询充值记录列表
     * 
     * @param recharge 充值记录
     * @return 充值记录
     */
    @Override
    public List<Recharge> selectRechargeList(Recharge recharge)
    {
        return rechargeMapper.selectRechargeList(recharge);
    }

    /**
     * 新增充值记录
     * 
     * @param recharge 充值记录
     * @return 结果
     */
    @Override
    public int insertRecharge(Recharge recharge)
    {
        //添加充值记录表的同时要修改用户数据表
        recharge.setRechargeTime(DateUtils.getNowDate());
        User dbUser = userMapper.selectUserByUserId(recharge.getUserId());
        dbUser.setPackId(recharge.getPackId());
        userMapper.updateUser(dbUser);  //修改用户记录表
        return rechargeMapper.insertRecharge(recharge);
    }

    /**
     * 修改充值记录
     * 
     * @param recharge 充值记录
     * @return 结果
     */
    @Override
    public int updateRecharge(Recharge recharge)
    {
        return rechargeMapper.updateRecharge(recharge);
    }

    /**
     * 批量删除充值记录
     * 
     * @param rechargeIds 需要删除的充值记录主键
     * @return 结果
     */
    @Override
    public int deleteRechargeByRechargeIds(Long[] rechargeIds)
    {
        return rechargeMapper.deleteRechargeByRechargeIds(rechargeIds);
    }

    /**
     * 删除充值记录信息
     * 
     * @param rechargeId 充值记录主键
     * @return 结果
     */
    @Override
    public int deleteRechargeByRechargeId(Long rechargeId)
    {
        return rechargeMapper.deleteRechargeByRechargeId(rechargeId);
    }
}
